﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using System.Text.RegularExpressions;
//using OpenPhotoAlbum.BusinessLogics;

namespace OpenPhotoAlbum.DbAccess
{
    public partial class User
    {
		//private static Regex generalFilter;
		//private static Regex userNameFilter;
		//private static Regex passwordFilter;

        static User()
        {
			//FilterConfigReader reader = FilterConfigReader.Instance;
			//generalFilter = new Regex(reader.ReadGeneralFilter(), RegexOptions.Compiled);
			//userNameFilter = new Regex(reader.ReadUserNameFilter(), RegexOptions.Compiled);
			//passwordFilter = new Regex(reader.ReadPasswordFilter(), RegexOptions.Compiled);
        }

        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
			//if (action == System.Data.Linq.ChangeAction.Insert)
			//{
			//    if (UserManager.Instance.IsUserNameUsed(this.UserName))
			//    {
			//        throw new DuplicatedUserNameException();
			//    }
			//    if (generalFilter.IsMatch(this.UserName) || userNameFilter.IsMatch(this.UserName))
			//    {
			//        throw new InvalidUserNameException();
			//    }
			//    if (passwordFilter.IsMatch(this.UserPassword))
			//    {
			//        //throw new InvalidPasswordException();
			//    }
			//}
			//else if (action == System.Data.Linq.ChangeAction.Update)
			//{
			//    if (passwordFilter.IsMatch(this.UserPassword))
			//    {
			//        //throw new InvalidPasswordException();
			//    }
			//}
        }
    }

	//public class DuplicatedUserNameException : Exception { }

	//public class InvalidPasswordException : Exception { }

	//public class InvalidUserNameException : Exception { }
}
